﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using He.Common;

namespace He.Web.manage.job
{
    public partial class list : He.Web.UI.Manage
    {
        protected int pageSize = 12;
        protected int page;
        protected int pcount;
        protected string keywords;
        protected void Page_Load(object sender, EventArgs e)
        {
            page = GetInt("page", 0);
            keywords = GetString("keywords");
            if (!IsPostBack)
            {
                chkLoginLevel("viewjob");

                CookieHelper.Set("LastListUrl", Request.RawUrl);    //保存最后一次访问的列表页Url

                RptBind();
            }
        }

        #region 数据绑定
        private void RptBind()
        {
            this.txtKeywords.Text = this.keywords;
            BLL.job bll = new BLL.job();
            string strWhere = CombSqlTxt(this.keywords) + string.Format(" and lang='{0}'", lang);
            rptList.DataSource = bll.GetPageList(pageSize, page, strWhere, "sort_id asc,id desc");
            rptList.DataBind();
            pcount = bll.GetRecordCount(strWhere);
        }
        #endregion

        //查询
        protected void btnSelect_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx?" + CombUrlTxt(txtKeywords.Text.Trim()) + "page=0&lang=" + lang);
        }

        //删除
        protected void lbtnDel_Click(object sender, EventArgs e)
        {
            chkLoginLevel("deljob");
            BLL.job bll = new BLL.job();
            for (int i = 0; i < rptList.Items.Count; i++)
            {
                CheckBox cb = (CheckBox)rptList.Items[i].FindControl("Check");
                int id = int.Parse(((HiddenField)rptList.Items[i].FindControl("HiddenId")).Value);
                if (cb.Checked)
                {
                    Model.job model = bll.GetModel(id);
                    bll.Delete(id);
                }
            }
            SaveLogs("[人才招聘管理]批量删除");
            JscriptPrint("批量删除成功啦！", Request.RawUrl, "Success");
        }

        //保存排序
        protected void lbtnSave_Click(object sender, EventArgs e)
        {
            chkLoginLevel("editjob");
            BLL.job bll = new BLL.job();
            for (int i = 0; i < rptList.Items.Count; i++)
            {
                CheckBox cb = (CheckBox)rptList.Items[i].FindControl("Check");
                int id = int.Parse(((Label)rptList.Items[i].FindControl("lb_id")).Text);
                int sortId;
                if (!int.TryParse(((TextBox)rptList.Items[i].FindControl("txtSortId")).Text.Trim(), out sortId))
                {
                    sortId = 99;
                }
                bll.UpdateField(id, "sort_id=" + sortId);
            }
            SaveLogs("[人才招聘管理]批量保存排序");
            JscriptPrint("排序保存成功啦！", Request.RawUrl, "Success");
        }

    }
}
